<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../css/style.css">
    <link rel="icon" href="../img/asset-favico.ico">
    <!-- 引入组件库 -->
    <script src="../plugins/datapicker/datePicker.js"></script>

    <script src="../plugins/echarts/echarts.js"></script>
    <script src="../plugins/healthmobile.js"></script>
    <script src="../js/vue.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script>Vue.config.productionTip = false</script>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>统计分析
            <small>会员数量</small>
        </h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>统计分析</el-breadcrumb-item>
            <el-breadcrumb-item>会员数量</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <!--日期选择输入框-->
            起始日期：<input type="date" v-model="dateInfo.beginDate">
            终止日期：<input type="date" v-model="dateInfo.endDate">
            <input type="button" value="查看" @click="submitDate()">
            <hr/>
            <!--为 ECharts 准备一个具备大小（宽高）的 DOM -->
            <div id="chart1" style="height:600px;"></div>
        </div>
    </div>
</div>
<script type="text/javascript">
    var vue = new Vue({
        el: '#app',
        data: {
            // 日期控件的选择信息，起始日期：beginDate、终止日期：endDate
            dateInfo: {
                beginDate: null,
                endDate: null
            }
        },
        mounted() {
            // 清除掉上一次的Echarts实例
            document.getElementById('chart1').removeAttribute('_echarts_instance_');
            // 调用方法重新初始化Echarts实例，然后发送请求查询数据，将响应数据赋值给折线图
            this.submitDate();
        },
        methods: {
            //提交日期
            submitDate() {
                //拿到用户选择的日期做校验
                var beginDate = this.dateInfo.beginDate;
                var endDate = this.dateInfo.endDate;
                if (beginDate == null) {
                    beginDate = this.getNowFormatDate();
                }
                // 若终止日期小于起始日期则违法
                if (endDate < beginDate) {
                    this.$message.error("终止日期不能比起始日期小！");
                    return false;
                }
                // 基于准备好的dom，初始化echarts实例
                var myChart1 = echarts.init(document.getElementById('chart1'));

                //发送ajax请求，提交日期数据到后台进行业务处理
                axios.post("/member/getMemberByTimeQuantum.do", this.dateInfo).then((res) => {
                    if (res.data.flag) {
                        //查询成功，显示折线图
                        myChart1.setOption(
                            {
                                title: {
                                    text: '会员数量'
                                },
                                tooltip: {},
                                legend: {
                                    data: ['会员数量']
                                },
                                xAxis: {
                                    data: res.data.data.months//动态数据,月份
                                },
                                yAxis: {
                                    type: 'value'
                                },
                                series: [{
                                    name: '会员数量',
                                    type: 'line',
                                    data: res.data.data.memberCount//动态数据，月会员数
                                }]
                            });
                    } else {
                        //查询失败，提示信息
                        this.$message.error(res.data.message);
                    }
                });
            },
            // 获取当前时间
            getNowFormatDate() {
                var date = new Date();
                var seperator1 = "-";
                var year = date.getFullYear();
                var month = date.getMonth() + 1;
                var strDate = date.getDate();
                if (month >= 1 && month <= 9) {
                    month = "0" + month;
                }
                if (strDate >= 0 && strDate <= 9) {
                    strDate = "0" + strDate;
                }
                var currentdate = year + seperator1 + month + seperator1 + strDate;
                return currentdate;
            }
        }
    });

</script>
</body>

</html>
